<?php

namespace app\controller;

use app\service\BookType as BookTypeService;
use support\Request;
use think\Exception;

class BookType
{
    public $bookTypeService;

    public function __construct(BookTypeService $BookTypeService)
    {
        $this->bookTypeService = $BookTypeService;
    }

    /**
     * 创建知识库
     * @param Request $request
     * @return \support\Response|void
     * @throws \exception
     */
    public function create(Request $request)
    {
        try {
            $param = $request->all();
            $param['data']['tenant_id'] = $request->getTenantId();
            $param['data']['created_by'] = $request->getCurrentUserId();
            $res = $this->bookTypeService->create($param['data']);
            return json(success_response('', $res));
        } catch (Exception $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 更新知识库
     * @param Request $request
     * @return \support\Response|void
     * @throws \exception
     */
    public function update(Request $request)
    {
        try {
            $param = $request->all();
            $param['data']['created_by'] = $request->getCurrentUserId();
            $param['data']['tenant_id'] = $request->getTenantId();
            $res = $this->bookTypeService->update($param['data']);
            return json(success_response('', $res));
        } catch (Exception $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 删除知识库
     * @param Request $request
     * @return \support\Response|void
     * @throws \exception
     */
    public function delete(Request $request)
    {
        try {
            $param = $request->all();
            $param['param']['filter']['created_by'] = $request->getCurrentUserId();
            $param['param']['filter']['tenant_id'] = $request->getTenantId();
            $res = $this->bookTypeService->delete($param['param']['filter']);
            return json(success_response('', $res));
        } catch (Exception $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

}